package com.example.service.impl;

import com.example.entiy.SMSCode;
import com.example.service.SMSService;
import com.example.uilt.CodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class SMSServiceimpl implements SMSService {

    @Autowired
    private CodeUtil codeUtil;
    @Override
    //@Cacheable(value="smsCode",key="#tele")// 不适用缓存，因为既存也取值
    @CachePut(value = "smsCode",key="#tele")
    public String sendCode(String tele) {
        String code = codeUtil.generatorCode(tele);

        return code;
    }

    @Override
    public boolean check(SMSCode smsCode) {
        // 取出传入的验证码与传递过来的验证啊比较，如果同样，则返回true，否则返回false
        String code = smsCode.getCode();
        String caheCode = codeUtil.getCode(smsCode.getTele());
        return caheCode.equals(code);
    }
}
